<template>
  <el-container class="notice-layout">
    <el-header class="notice-title">
      <el-tag v-if="detail.select === 1" type="danger">置顶</el-tag>
      <span class="title-text">{{ detail.noticeTitle }}</span>
    </el-header>

    <el-main class="notice-info">
      <div class="content" v-html="detail.noticeContent"></div>
      <div class="description">{{ detail.description }}</div>
      <span class="item">{{ detail.remark }} 
        <el-date-picker v-model="formattedDate" type="datetime"
          format="YYYY-MM-DD HH:mm:ss" disabled></el-date-picker>
      </span>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getNotice } from '@/api/wallpaper/notice.js'
import { useRoute, useRouter } from 'vue-router'



const route = useRoute()
const router = useRouter()

const detail = ref({})
const formattedDate = ref('')
let noticeId

onMounted(() => {
  noticeId = Number(route.params.id)
  getNoticeDetail()
})

const getNoticeDetail = async () => {
  try {
    const res = await getNotice(noticeId)
    if (res.data) {
      detail.value = res.data
      formattedDate.value = new Date(detail.value.createTime).toLocaleString()
    } else {
      ElMessage.warning('通知详情为空')
    }
  } catch (error) {
    ElMessage.error('获取通知详情失败')
  }
}
</script>

<style lang="scss" scoped>
.notice-layout {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
  height: 60vh;

  .notice-title {
    font-size: 26px;
    color: #2c3e50;
    line-height: 1.5em;
    padding-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .el-tag {
      margin-right: 10px;
    }

    .title-text {
      padding-left: 10px;
    }
  }

  .notice-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    color: #34495e;
    font-size: 18px;
    margin-bottom: 20px;
    overflow-y: auto;
    max-height: 50vh;

    .item {
      padding-bottom: 10px;
    }
  }

  .content {
    width: 100%;
    height: 50vh;
    overflow-y: auto;
    padding: 20px;
    background-color: #ecf0f1;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  .description {
    margin-bottom: 15px;
    font-weight: bold;
    font-size: 20px;
  }
}
</style>